<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0"/>
    <!-- If you are using the CSS version, only link these 2 files, you may add app.css to use for your overrides if you like -->
    <link rel="stylesheet" href="amazeui/css/amazeui.min.css">
    <link rel="stylesheet" type="text/css" href="css/setting.css">
    <!-- If you are using the gem version, you need this only -->
</head>
<body>
<div class="login_from">
    <from class="am-form">
        <fieldset>
            <legend>vpn设置</legend>
        </fieldset>
        <div class="am-form-group">
            <input type="text" id="ip" placeholder="服务器地址" value=""/>
        </div>
        <div class="am-form-group">
            <input type="text" id="name" placeholder="账户名称" value=""/>
        </div>
        <div class="am-form-group">
            <input type="password" id="pass" placeholder="密码" value=""/>
        </div>
        <div class="am-form-group">
            <button type="button" class="am-btn am-btn-primary am-btn-block" onclick="saveButtonOnClick()">保存并连接VPN
            </button>
        </div>
    </from>
    <div id='loginTip' class="am-alert am-alert-warning" data-am-alert style="display:none">
        <button type="button" class="am-close">&times;</button>
        <p>登录异常，请重新登录</p>
    </div>
</div>

<script src="amazeui/js/jquery.min.js"></script>
<script src="amazeui/js/amazeui.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script src="js/setting.js"></script>
<script>
    function saveButtonOnClick() {
        var networkState = navigator.connection.type;
        if (networkState == Connection.NONE || networkState == Connection.UNKNOWN) {
            $('#loginTip p:first').text("网络断开,请检查网络");
            $("#loginTip").show();
            $('#loginTip').delay(6000).hide(0);
        } else {
            $.AMUI.progress.start();
            var ip = $('#ip').val();
            var passport = $('#name').val();
            var password = $('#pass').val();
            setting.setVpn(ip, passport, password);
            localStorage.VPN_REMEMBER_ME_COOKIE_ = JSON.stringify({ip: ip, name: passport, pass: ""});
        }
    }

    var autoLogin = setting.getQueryStringByName("autoLogin");
    if (autoLogin) {
        setting.initialize(autoLogin);
    }
    else {
        setting.initialize();
    }
</script>
</body>
</html>